<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遍历对象each方法</title>
    <script src="../jQuery.js"></script>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
        $(function(){
            var arr=["red","blue","yellow"];
            var sum=0;
            //$("div").css("color","red"); 隐式迭代
        $("div").each(function(index,domEle){
            //回调函数第一个参数一定是索引号 可以直接定义索引号名:index改为 i
            console.log(index); //自动分配索引 0 1 2
            //回调函数第二个参数一定是dom元素对象
            console.log(domEle);
            //domEle.css("color") dom对象没有css方法
            $(domEle).css("color",arr[index]);
            sum+=parseInt($(domEle).text());  
            //得到每个div里面的值,最后求得总和
        })
        console.log(sum);//6
        })
        
    </script>
</body>
</html>